﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KylinORM.Data;
using KylinORM.Mapper.Base;
using System.Data;

namespace KylinORM.Mapper
{
    /// <summary>
    /// 实体映射器
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public interface ISimpleMapper<T> : IMapper, ISubmitable, ILinqable<T>, IEnumerable<T> where T : new()
    {
        /// <summary>
        /// 目标实体
        /// </summary>
        T Entity { get; }

        #region 标准查询
        /// <summary>
        /// 查询实体
        /// </summary>
        /// <returns></returns>
        List<T> Select();
        /// <summary>
        /// 查询实体，仅返回指定的字段
        /// </summary>
        /// <param name="fields">要返回的实体字段列表</param>
        /// <returns></returns>
        List<T> Select(string fields);
        /// <summary>
        /// 查询实体，使用指定的Sql语句
        /// </summary>
        /// <param name="sql">完整Sql语句</param>
        /// <param name="parms">查询参数</param>
        /// <returns></returns>
        List<T> Select(string sql, params object[] parms);
        /// <summary>
        /// 查询实体，使用指定的Sql语句
        /// </summary>
        /// <typeparam name="TEntity">返回的数据类型</typeparam>
        /// <param name="sql">完整Sql语句</param>
        /// <param name="parms">查询参数</param>
        /// <returns></returns>
        List<TEntity> Select<TEntity>(string sql, params object[] parms) where TEntity : new();

        /// <summary>
        /// 使用指定查询条件，查询实体
        /// </summary>
        /// <param name="queryEntity">作为查询条件的实体</param>
        /// <returns></returns>
        List<T> Select(T queryEntity);
        /// <summary>
        /// 使用指定查询条件，查询实体，仅返回指定的字段
        /// </summary>
        /// <param name="queryEntity"></param>
        /// <param name="fields">要返回的实体字段列表</param>
        /// <returns></returns>
        List<T> Select(T queryEntity, string fields);
        #endregion

        #region 主键查询
        /// <summary>
        /// 使用指定的主键值查询
        /// </summary>
        /// <param name="keyValues"></param>
        /// <returns></returns>
        T Find(params object[] keyValues);
        #endregion

        #region 分页查询
        /// <summary>
        /// 查询实体并分页，使用默认查询条件
        /// </summary>
        /// <param name="page">页码，从1开始</param>
        /// <param name="itemsPerPage">每页行数</param>
        /// <returns></returns>
        DataResult<T> SelectPage(int page, int itemsPerPage);
        /// <summary>
        /// 查询实体并分页，使用自定义请求
        /// </summary>
        /// <param name="page">页码，从1开始</param>
        /// <param name="itemsPerPage">每页行数</param>
        /// <param name="sql">完整Sql语句</param>
        /// <param name="parms">查询参数</param>
        /// <returns></returns>
        DataResult<T> SelectPage(int page, int itemsPerPage, string sql, params object[] parms);
        /// <summary>
        /// 查询实体并分页，使用自定义请求
        /// </summary>
        /// <typeparam name="TEntity">返回的数据类型</typeparam>
        /// <param name="page">页码，从1开始</param>
        /// <param name="itemsPerPage">每页行数</param>
        /// <param name="sql">完整Sql语句</param>
        /// <param name="parms">查询参数</param>
        /// <returns></returns>
        DataResult<TEntity> SelectPage<TEntity>(int page, int itemsPerPage, string sql, params object[] parms) where TEntity : new();

        /// <summary>
        /// 使用指定查询条件，查询实体并分页，使用默认查询条件
        /// </summary>
        /// <param name="queryEntity">作为查询条件的实体</param>
        /// <param name="page">页码，从1开始</param>
        /// <param name="itemsPerPage">每页行数</param>
        /// <returns></returns>
        DataResult<T> SelectPage(T queryEntity, int page, int itemsPerPage);
        #endregion

        #region 排序
        /// <summary>
        /// 查询实体，使用指定的排序字段
        /// </summary>
        /// <param name="fields">排序字段</param>
        /// <returns></returns>
        List<T> OrderBy(string fields);
        /// <summary>
        /// 查询实体，使用指定的排序字段
        /// </summary>
        /// <param name="fields">排序字段</param>
        /// <returns></returns>
        List<T> OrderByDescending(string fields);

        /// <summary>
        /// 使用指定查询条件，查询实体，使用指定的排序字段
        /// </summary>
        /// <param name="queryEntity"></param>
        /// <param name="fields">排序字段</param>
        /// <returns></returns>
        List<T> OrderBy(T queryEntity, string fields);
        /// <summary>
        /// 使用指定查询条件，查询实体，使用指定的排序字段
        /// </summary>
        /// <param name="queryEntity"></param>
        /// <param name="fields">排序字段</param>
        /// <returns></returns>
        List<T> OrderByDescending(T queryEntity, string fields);
        #endregion        
    }

}
